using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace Betarium.PotonEditor
{
	public class ToolInfoCircle : ToolInfo
	{
		public ToolInfoCircle(EditViewForm form)
			: base(form)
		{
		}

		public override void OnMouseDown(object sender, MouseEventArgs e)
		{
			m_Form.SelectState.OnMouseDown(sender, e);
		}

		public override void OnMouseUp(object sender, MouseEventArgs e)
		{
			bool bMouseLeftDown = m_Form.SelectState.MouseLeftDown;
			m_Form.SelectState.OnMouseUp(sender, e);
			if (bMouseLeftDown
				&& e.Button == MouseButtons.Left
				&& m_Form.SelectState.MouseMoved)
			{
                this.m_Form.AddUndo();
                using (Graphics graph = Graphics.FromImage(m_Form.Image))
				{
					OnDraw(graph);
				}
				SetModified();
			}
		}
		public override void OnMouseMove(object sender, MouseEventArgs e)
		{
			m_Form.SelectState.OnMouseMove(sender, e);
			if (m_Form.SelectState.MouseLeftDown)
			{
				m_Form.Cursor = Cursors.Cross;
			}
			else
			{
				m_Form.Cursor = Cursors.Arrow;
			}
		}
		public override void OnPaint(object sender, PaintEventArgs e)
		{
			if (m_Form.SelectState.MouseLeftDown)
			{
				OnDraw(e.Graphics);
			}
		}
		public override void OnDraw(Graphics graph)
		{
			if (!m_Form.SelectState.MouseMoved)
				return;
			switch (ColorState.FillMode)
			{
				case PaintInfo.FillModes.Outer:
					graph.DrawEllipse(new Pen(m_Form.PaintState.MainColor), m_Form.SelectState.MouseMoveRect);
					break;
				case PaintInfo.FillModes.Both:
					graph.FillEllipse(new SolidBrush(m_Form.PaintState.SubColor), m_Form.SelectState.MouseMoveRect);
					graph.DrawEllipse(new Pen(m_Form.PaintState.MainColor), m_Form.SelectState.MouseMoveRect);
					break;
				case PaintInfo.FillModes.Inner:
					graph.FillEllipse(new SolidBrush(m_Form.PaintState.MainColor), m_Form.SelectState.MouseMoveRect);
					break;
			}
		}
	}
}
